package is.model.bean;

import is.NullUtil;
import is.interfaces.Bean;
import is.model.exceptions.EmptyValueException;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author aspr0
 */
public class Employee extends AbstractBean implements Bean, Cloneable
{
    private String lastName;
    private String firstName;
    private String middleName;
    private Integer departmentId;
    private Integer telephone;
    private Float salary;

    public Employee()
    {
        // nullary constructor need to escape from instantiation exception
        tableName = "employee";
        fields = new String[]
        {
            "lastName", "firstName", "middleName", "departmentId", "telephone", "salary"
        };
    }

    public Integer getDepartmentId()
    {
        return departmentId;
    }

    public void setDepartmentId(Integer departmentId) throws EmptyValueException
    {
        this.departmentId = departmentId;
    }

    public String getFirstName()
    {
        return firstName;
    }

    public void setFirstName(String firstName) throws EmptyValueException
    {
        this.firstName = firstName;
    }

    public String getLastName()
    {
        return lastName;
    }

    public void setLastName(String lastName) throws EmptyValueException
    {
        this.lastName = lastName;
    }

    public String getMiddleName()
    {
        return middleName;
    }

    public void setMiddleName(String middleName) throws EmptyValueException
    {
        this.middleName = middleName;
    }

    public Float getSalary()
    {
        return salary;
    }

    public void setSalary(Float salary) throws EmptyValueException
    {
        this.salary = salary;
    }

    public Integer getTelephone()
    {
        return telephone;
    }

    public void setTelephone(Integer telephone) throws EmptyValueException
    {
        this.telephone = telephone;
    }

    @Override
    public String[] getValues()
    {
        return new String[]
                {
                    NullUtil.toString(lastName),
                    NullUtil.toString(firstName),
                    NullUtil.toString(middleName),
                    NullUtil.toString(departmentId),
                    NullUtil.toString(telephone),
                    NullUtil.toString(salary)
                };
    }

    @Override
    public void processResultSet(ResultSet resultSet) throws SQLException
    {
        id = resultSet.getInt(KEY_FIELD);
        lastName = resultSet.getString(fields[0]);
        firstName = resultSet.getString(fields[1]);
        middleName = resultSet.getString(fields[2]);
        departmentId = resultSet.getInt(fields[3]);
        telephone = resultSet.getInt(fields[4]);
        salary = resultSet.getFloat(fields[5]);
    }
}
